﻿CREATE PROCEDURE [dbo].[SaveTriggerInstance]
(@WorkflowTriggerInstanceID varchar(50),
@TriggerComponentID varchar(50),
@WorkflowDesignID varchar(50),
@TriggerType int,
@TimeSpanUnit int,
@Interval int, 
@FirstStartTime datetime,
@LastRunTime datetime,
@NextRunTime datetime,
@IsActive bit) as 
begin
	declare @count int
	set @count=(select count (*) from WorkflowTriggerInstance where WorkflowTriggerInstanceID=@WorkflowTriggerInstanceID)
	if(@count>0)
	begin
		update WorkflowTriggerInstance 
		set
			TriggerComponentID=@TriggerComponentID,
			WorkflowDesignID=@WorkflowDesignID,
			TriggerType=@TriggerType,
			TimeSpanUnit=@TimeSpanUnit,
			Interval=@Interval,
			FirstStartTime=@FirstStartTime,
			LastRunTime=@LastRunTime,
			NextRunTime=@NextRunTime,
			IsActive=@IsActive 
		where 
			WorkflowTriggerInstanceID=@WorkflowTriggerInstanceID
	end
	else
	begin
		insert into WorkflowTriggerInstance 
		(WorkflowTriggerInstanceID,
		TriggerComponentID,
		WorkflowDesignID,
		TriggerType,
		TimeSpanUnit,
		Interval,
		FirstStartTime,
		LastRunTime,
		NextRunTime,
		IsActive) values 
		(@WorkflowTriggerInstanceID,
		@TriggerComponentID,
		@WorkflowDesignID,
		@TriggerType,
		@TimeSpanUnit,
		@Interval,
		@FirstStartTime,
		@LastRunTime,
		@NextRunTime,
		@IsActive)
	end
end


